{ "cells": [ { "cell_type": "markdown", "id": "57a92274", "metadata": {}, "source": [ "# Load, Fuel Mix, and LMP Data\n", "\n", "This notebook walk through how to use `gridstatus` to access to the data availabe on [OASIS](http://oasis.caiso.com/).\n", "\n", "While we will be using CAISO in this example, most of this API will also work with all other ISOs." ] }, { "cell_type": "code", "execution_count": 1, "id": "3599dfce", "metadata": {}, "outputs": [], "source": [ "import gridstatus\n", "import pandas as pd\n", "import plotly.express as px" ] }, { "cell_type": "code", "execution_count": 2, "id": "854ac803", "metadata": {}, "outputs": [], "source": [ "caiso = gridstatus.CAISO()" ] }, { "cell_type": "markdown", "id": "4612c2d0", "metadata": {}, "source": [ "## Historical Fuel Mix" ] }, { "cell_type": "code", "execution_count": 3, "id": "d35b27ed", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 1696/1696 [15:48<00:00, 1.79it/s]\n" ] } ], "source": [ "start = pd.Timestamp(\"April 10, 2018\").normalize()\n", "end = pd.Timestamp.now().normalize()\n", "mix_df = caiso.get_fuel_mix(start, end=end, verbose=False)" ] }, { "cell_type": "code", "execution_count": 9, "id": "662f53d4", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": "Jul 2018Jan 2019Jul 2019Jan 2020Jul 2020Jan 2021Jul 2021Jan 2022Jul 202205M10M15M20M25MvariableNatural GasImportsSolarWindNuclearLarge HydroGeothermalBiomassSmall HydroBiogasBatteriesCoalOtherFuel Mix by Month - CAISOTimevalue" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hourly_mix = mix_df.set_index(\"Time\").resample(\"H\").mean()\n", "monthly_mix = hourly_mix.resample(\"MS\").sum().reset_index()[1:-1]\n", "top_sources = (\n", " monthly_mix[monthly_mix.columns[1:]]\n", " .sum()\n", " .sort_values(ascending=False)\n", " .index.tolist()\n", ")\n", "fig = px.bar(monthly_mix, x=\"Time\", y=top_sources, title=\"Fuel Mix by Month - CAISO\")\n", "fig.show(\"svg\", width=1200, height=600)" ] }, { "cell_type": "markdown", "id": "bb652292", "metadata": {}, "source": [ "## Historical Load " ] }, { "cell_type": "code", "execution_count": 10, "id": "27098731", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 1696/1696 [13:27<00:00, 2.10it/s]\n" ] } ], "source": [ "start = pd.Timestamp(\"April 10, 2018\").normalize()\n", "end = pd.Timestamp.now().normalize()\n", "load_df = caiso.get_load(start, end=end)" ] }, { "cell_type": "code", "execution_count": 11, "id": "4eb4c3e3", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": "Jul 2018Jan 2019Jul 2019Jan 2020Jul 2020Jan 2021Jul 2021Jan 2022Jul 202216M18M20M22M24MMonthly Load - CAISOTimeLoad" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "hourly_load = load_df.set_index(\"Time\").resample(\"H\").mean()\n", "monthly_load = hourly_load.resample(\"MS\").sum().reset_index()[1:-1]\n", "fig = px.line(monthly_load, x=\"Time\", y=\"Load\", title=\"Monthly Load - CAISO\")\n", "fig.show(\"svg\", width=1200, height=600)" ] }, { "cell_type": "markdown", "id": "7193787c", "metadata": {}, "source": [ "## Historical Locational Marginal Pricing (LMP)\n", "\n", "You can supply whatever nodes or market you'd like, but for now let's download data for 3 trading hubs in the Day Head Hourly Market. \n", "\n", "Note: CAISO only provides last 39 months of data." ] }, { "cell_type": "code", "execution_count": 12, "id": "86cb97a7", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 35/35 [22:04<00:00, 37.85s/it]\n" ] } ], "source": [ "start = pd.Timestamp(\"Jan 1, 2020\").normalize()\n", "end = pd.Timestamp.now().normalize()\n", "\n", "locations = [\"TH_NP15_GEN-APND\", \"TH_SP15_GEN-APND\", \"TH_ZP26_GEN-APND\"]\n", "\n", "lmp_df = caiso.get_lmp(\n", " start=start, end=end, market=\"DAY_AHEAD_HOURLY\", locations=locations, sleep=5\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "39c891f9", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": "Jul 2020Jan 2021Jul 2021Jan 2022Jul 2022020406080100120140160LocationTH_NP15_GEN-APNDTH_SP15_GEN-APNDTH_ZP26_GEN-APNDNegative LMPs per Month - CAISOTimeNumber of Negative LMPs" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "negative_lmps = lmp_df[lmp_df[\"LMP\"] < 0].set_index(\"Time\")\n", "negative_per_month = (\n", " negative_lmps.groupby(\"Location\").resample(\"MS\")[\"LMP\"].count().reset_index()\n", ")\n", "fig = px.bar(\n", " negative_per_month,\n", " x=\"Time\",\n", " y=\"LMP\",\n", " title=\"Negative LMPs per Month - CAISO\",\n", " color=\"Location\",\n", ")\n", "fig.update_yaxes(title=\"Number of Negative LMPs\")\n", "fig.show(\"svg\", width=1200, height=600)" ] }, { "cell_type": "markdown", "id": "10f2ba2a", "metadata": {}, "source": [ "## Gas Prices\n", "\n", "CAISO also publish information about gas prices and greenhouse gas allownces that we will download" ] }, { "cell_type": "code", "execution_count": 14, "id": "917a3e07", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 11/11 [01:03<00:00, 5.78s/it]\n" ] } ], "source": [ "start = start = pd.Timestamp(\"Jan 01, 2022\").normalize()\n", "end = pd.Timestamp.now().normalize()\n", "\n", "gas_price_df = caiso.get_gas_prices(start=start, end=end, fuel_region_id=\"FRPGE2GHG\")" ] }, { "cell_type": "code", "execution_count": 15, "id": "f4168867", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 11/11 [01:03<00:00, 5.75s/it]\n" ] } ], "source": [ "start = start = pd.Timestamp(\"Jan 01, 2022\").normalize()\n", "end = pd.Timestamp.now().normalize()\n", "\n", "ghg_df = caiso.get_ghg_allowance(start=start, end=end)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.2 64-bit ('gridstatus')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.2" }, "vscode": { "interpreter": { "hash": "49f14642123d0cc1afa9fa45716ed5f1e915189c28b01efe02a8b7ec3c0a3fce" } } }, "nbformat": 4, "nbformat_minor": 5 }